<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<% String path = request.getContextPath();
  request.setAttribute("path",path);%>
<!DOCTYPE>
<html>
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>酒店管理系统 - 添加用户</title>
  <meta name="keywords" content="">
  <meta name="description" content="">

  <link rel="shortcut icon" href="favicon.ico">
  <link href="${path}/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
  <link href="${path}/css/font-awesome.css?v=4.4.0" rel="stylesheet">
  <script src="https://unpkg.com/element-ui/lib/index.js"></script>
  <!-- Data Tables -->
  <link href="${path}/css/plugins/dataTables/dataTables.bootstrap.css"
        rel="stylesheet">
  <link href="${path}/css/animate.css" rel="stylesheet">
  <link href="${path}/css/style.css?v=4.1.0" rel="stylesheet">

</head>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
  <div class="row">
    <div class="col-sm-12">
      <div class="ibox float-e-margins">
        <div class="ibox-title">
          <h5>添加用户</h5>
        </div>
        <div class="ibox-content">
          <form method="post" class="form-horizontal" id="commentForm" action="${path}/client/clientAdd">
            <div class="form-group">
              <label class="col-sm-3 control-label">用户名</label>
              <div class="col-sm-7">
                <input type="text" class="form-control" name="username"  onblur="checkName(this.value)"> <p id="nameCheck"></p>
              </div>
            </div>
            <div class="form-group">
              <label class="col-sm-3 control-label">密码</label>
              <div class="col-sm-7">
                <input type="password" class="form-control" id="password"  name="password" minlength="6" required >
              </div>
            </div>
            <div class="form-group">
              <label class="col-sm-3 control-label">头像</label>
              <div class="col-sm-7" id="mydiv">
                <input type="file" class="form-control" id="kfImgs"  name="kfImgs" onchange="fileUpload()" style="display: none">
                <img src="../../img/hsxr.png" id="myImg" width="80px" height="80px" style="border: solid 1px rgba(128,128,128,0.56);float: left" onclick=$("#kfImgs").click()>
                <input type="hidden" id="fileImg" name="via" >
              </div>
            </div>

            <div class="form-group">
              <label class="col-sm-3 control-label">真实姓名</label>
              <div class="col-sm-7">
                <input type="text" class="form-control"  name="name" >
              </div>
            </div>
            <div class="form-group">
              <label class="col-sm-3 control-label">性别</label>
              <div class="col-sm-7">
                <div class="radio i-checks">
                  <label>
                    <input type="radio" value="man" name="sex"><i></i>男</label>
                  <i style="margin-left: 25px"></i>
                  <label>
                    <input type="radio" value="woman" name="sexr" > <i></i>女</label>
                </div>
              </div>
            </div>

            <div class="form-group">
              <label class="col-sm-3 control-label">邮箱地址</label>
              <div class="col-sm-7">
                <input type="email" class="form-control"  name="email" >
              </div>
            </div>
            <div class="form-group">
              <label class="col-sm-3 control-label">电话号码</label>
              <div class="col-sm-7">
                <input type="text" class="form-control"  name="phone" >
              </div>
            </div>
            <div class="form-group">
              <label class="col-sm-3 control-label">状态</label>
              <div class="col-sm-7">
                <label>
                  <input type="radio" value="0" name="status" >删除</label>
                <i style="margin-left: 25px"></i>
                <label>
                  <input type="radio" value="1" name="status" >启用</label>
                <i style="margin-left: 25px"></i>
                <label>
                  <input type="radio" value="2" name="status" >禁用</label>
              </div>
            </div>
            <div class="hr-line-dashed"></div>
            <div class="form-group">
              <div class="col-sm-4 col-sm-offset-8">
                <button class="btn btn-success" type="submit">添&nbsp;&nbsp;加</button>&nbsp;&nbsp;&nbsp;&nbsp;
                <button class="btn btn-white" type="reset" >取&nbsp;&nbsp;消</button>
              </div>
            </div>
          </form>
      </div>
    </div>
  </div>
</div>
</div>

<!-- 全局js -->
<script src="${path}/js/jquery.min.js?v=2.1.4"></script>
<script src="${path}/js/bootstrap.min.js?v=3.3.6"></script>
<script src="${path}/js/plugins/jeditable/jquery.jeditable.js"></script>

<!-- Data Tables -->
<script src="${path}/js/plugins/dataTables/jquery.dataTables.js"></script>
<script src="${path}/js/plugins/dataTables/dataTables.bootstrap.js"></script>

<!-- 自定义js -->
<script src="${path}/js/content.js?v=1.0.0"></script>

<!-- 表单验证 -->
<script src="${path}/js/plugins/validate/jquery.validate.min.js"></script>
<script src="${path}/js/plugins/validate/messages_zh.min.js"></script>

<!-- layer javascript -->
<script src="${path}/js/plugins/layer/layer.min.js"></script>
<script>
  $().ready(function() {
    $("#commentForm").validate();
  });
  $.validator.setDefaults({
    submitHandler: function() {
      parent.layer.alert('添加成功！',{icon: 1}),
              form.submit();
    }
  });
  function checkName(username){
    if(username!==""){
      $.ajax({
        type:"GET",
        url:"/client/checkUsername",
        data:"username="+username,
        dataType: "text",
        contentType:false,
        cache:false,
        processData:false,
        success:function (data){
          if (data==="true"){
            document.getElementById("nameCheck").innerText="✅"
          }else {
            document.getElementById("nameCheck").innerText="❌该用户名已经被注册"
          }
        }
      });
    }
  };

  function fileUpload(){
    var fileObj = $("#kfImgs");
    var fileEle=fileObj[0].files[0];
    var formData = new FormData();
    formData.append("file",fileEle);
    $.ajax({
      type:"post",
      url:"/kfRoom/fileUpload",
      data:formData,
      dataType: "json",
      contentType:false,
      cache:false,
      processData:false,
      success:function (data){
        var url=data.fileName;
        document.getElementById("myImg").src=url;
        document.getElementById("fileImg").value=url;
      }
    });
  }
</script>
</body>
</html>
